//
//  WebViewVC.swift
//  SmartPenSwift
//
//  Created by tql on 2021/3/4.
//

import UIKit
import WebKit

class WebViewVC: UIViewController {

    
    open  var strTitle : String? = ""
    open  var strUrl : String? = ""
    
    lazy var wkwebView :  WKWebView  = {
        
        let view : WKWebView = WKWebView.init()
        view.uiDelegate = self
        view.navigationDelegate = self
        return view
    }()
    lazy var activieyView : UIActivityIndicatorView = UIActivityIndicatorView.init(style: .large)
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = strTitle ?? ""
        
        self.view.addSubview(self.wkwebView)
        self.wkwebView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.view)
        }
        
        self.view.addSubview(self.activieyView)
        self.activieyView.snp.makeConstraints { (make) in
            make.center.equalTo(self.view)
        }
        
        
        
        
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        var requst : URLRequest?
        
        if ((self.strUrl?.hasPrefix("http")) == true) {
            requst = URLRequest.init(url: URL(string: strUrl!)!) as! URLRequest
            
        }else{
            requst = URLRequest.init(url: URL(fileURLWithPath: strUrl!)  ) as! URLRequest
        }

        self.wkwebView.load(requst!)
        
        
    }
}
extension WebViewVC : WKUIDelegate{
    
}

extension WebViewVC : WKNavigationDelegate{
    
}
